function* f() {
    for(let i = 0;true;i++) {
        let reset = yield i;
       
        if(reset) {
            i = -1;
        }
    }
}

let g = f();

console.log(g.next());
console.log(g.next());
console.log(g.next(true));
console.log(g.next());

console.log('-s----------------');

function* f1() {
    yield 1;
    yield* f();
    yield 'over';
}

let g1 = f1();

console.log(g1.next());
console.log(g1.next());
console.log(g1.next(true));
console.log(g1.next(true));


console.log('----+---');

function* fun() {
    yield 1;
    yield* [2,3,4];
    yield 5;
}
let arr = [...fun()] // [1,2,3,4,5]
console.log(arr);

console.log('---------------使用 generator 部署接口---');
function* addIterator(obj) {
    
    for(let key in obj) {
        yield [key,obj[key]];
    }
}

let obj = {
    name:'daxia',
    age:14,
    sex:'man'
}
let map = new Map(addIterator(obj));
console.log(map);

console.log('=------ 使用 generator 封装异步任务 ——-------');
const fetch = require('node-fetch');
